# 操控元素
# click()  
# send_keys()
# clear()
# get_attribute()  value  innerHTML  outerHTML innerText textContent

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from changliang import LUJING
import time

wd = webdriver.Chrome(service=Service(LUJING))
wd.get('https://www.byhy.net/cdn2/files/selenium/test3.html')
wd.implicitly_wait(10)

ele = wd.find_element(By.ID,'input1')
v1 = ele.get_attribute('value')
v2 = ele.get_attribute('outerHTML')
v3 = ele.get_attribute('innerHTML')
print(v1)
print(f'v2:{v2}')
print(v3)
# ele.clear()
# ele.send_keys('baiyueheiyu')
# time.sleep(3)

wd.get('https://y.qq.com/n/ryqq/toplist/27')
songlist = wd.find_element(By.CLASS_NAME,'songlist__list')
songs = songlist.find_elements(By.TAG_NAME,'li')
dict1 = {}
for song in songs:
    infos = song.find_elements(By.TAG_NAME,'div')
    flag = False
    for info in infos:
        if info.get_attribute('class') == 'songlist__rank':
            rank = info.find_element(By.TAG_NAME,'i')
            if rank.get_attribute('class') == 'icon_rank_up':
                flag = True
        elif info.get_attribute('class') == 'songlist__artist':
            artist = info.text
        elif info.get_attribute('class') == 'songlist__songname':
            song_name = info.text
        else:
            continue
    if flag:
        dict1[artist] = song_name

for k,v in dict1.items():
    print(f'{v:20}:{k:10}')